mdcmsfandomcom-20200214-history
The mdCMS template system
mdCMS features a fully dynamic template system. This template system may also be used in your own projects. It is released under the GNU GPL. For more information about using the mdCMS tempalte system in your own projects you may want to look at the basics below. The implemention of the mdCMS template system is documented too: mdCMS template system in your own projects. Please note that you should only look at the basics on this page. The documentation about the plugin loops is only for mdCMS and its not included in the external release of the template system! (The normal loops are included of course) mdCMS template system - Basics These basics are used as reference for the mdCMS template system, this means that you may use it as reference for creating templates for mdCMS, but also if you want to use the template system for your own projects. Variables Variables will be there for dynamic Values. The PHP Code defines what variables there are to use. "{tpl_var::title}" This will be replaced by the value of the variable (where title is the name of the variable) Loops Loops will be repeated untill the array is done. This means that everything between the start and the end of a loop will be repeated. Each run will have new values for the variables. In this way you can for example display a table or similar with dynamic content (Out of a MySQL DB for example). "{tpl_loop::abc}"* - Beginning of a loop with name 'abc' "{tpl_loop_end::abc}"* - End of the loop named 'abc' *For plugin loops please look at LINK HERE BLABLA. If / Else You can also use If / Else statements in templates. You can check dynamic variables using "(variablename)". Static content can be entered directly. To check if something is "" or nothing you have to use "(_nothing)". "{tpl_if::(vname):: ::value}" - Start of the If / else check "{tpl_else}" - else for the if / else check (Not required) "{tpl_endif}" - Endif - required! See below for some examples and the matching PHP expressions: Available expressions: (equal) != (not equal) < (smaller) <= (smaller or equal) > (bigger) >= (bigger or equal) <> (not equal) Code examples Here you will find some template code examples for easy understanding Variables Very easy example for variables. Code: You are logged in as {tpl_var::username} Output: You are logged in as Username1 Loops Example for loops and tables. Code: ID: Name: {tpl_loop::userlist} {tpl_var::userid} {tpl_var::username} {tpl_loop_end::userlist} Output: ID: Name: 1 Username1 2 Username2 3 Username3 If / Else Example for if / else statements. (As extension to the easy variable example) Code: {tpl_if::(username):: ::(_nothing)} You are not logged in {tpl_else} You are logged in as {tpl_var::username} {tpl_endif} Output: You are logged in as Username1 A user with username 'Username1' is logged in. You are not logged in Not logged in (Or the variable with name "username" was not set) If / Else for favicon Example for if / else statements. This should always be used for mdCMS templates! Code: {tpl_if::(favicon)::!=::(_nothing)} {tpl_endif} Output: Will add the code for the favicon ONLY if a favicon was set! If / Else + loop Example 2 for if / else statements and loops. (As extension to the loop example) It will output an array loop and give each user a icon (Admin or user). Code: Icon: ID: Name: {tpl_loop::userlist} {tpl_if::(userlevel):: ::administrator} {tpl_else} {tpl_endif} {tpl_var::userid} {tpl_var::username} {tpl_loop_end::userlist} Output: Icon: ID: Name: 1 Username1 2 Username2 3 Username3 As you can see Username1 is an administrator. The others are only users. Note: To create an elseif you only have to make multiple if statements: {tpl_if::(userlevel):: ::admin} {tpl_endif} {tpl_if::(userlevel):: ::mod} {tpl_endif} {tpl_if::(userlevel):: ::user} {tpl_endif}